package com.yangguang.huahui.mvp.model;

import com.yangguang.huahui.api.LoginApi;
import com.yangguang.huahui.entity.HttpResult;
import com.yangguang.huahui.entity.Login;
import com.yangguang.huahui.net.NetManager;
import com.yangguang.huahui.utils.SignUtil;

import java.util.HashMap;
import java.util.Map;

import okhttp3.ResponseBody;
import rx.Observable;

/**
 * Created by Administrator on 2017/3/1.
 */

public class LoginModel {
    //获取验证码
    public Observable<HttpResult> getCode(String phone){
        LoginApi server = NetManager.getInstance().create(LoginApi.class);
        return server.getCode(phone);
    }
    //登录
    public Observable<Login> login(String phone, int type, String password, String code, double lat, double lng){
        LoginApi server = NetManager.getInstance().create(LoginApi.class);
        Map<String, String> map = new HashMap<String, String>();
        map.put("phone", phone);
        map.put("type", String.valueOf(type));
        map.put("password", password);
        map.put("code", code);
        map.put("lat", String.valueOf(lat));
        map.put("lng", String.valueOf(lng));
        return server.login(phone, type, password, code, lat, lng, SignUtil.getSign(map));
    }
    //注册
    public Observable<Login> register(String phone, String code, String password, String imei, String phone_model,
                                             String phone_system, String phone_version, double lat, double lng){
        LoginApi server = NetManager.getInstance().create(LoginApi.class);
        Map<String, String> map = new HashMap<String, String>();
        map.put("phone", phone);
        map.put("password", password);
        map.put("code", code);
        map.put("imei", imei);
        map.put("phone_model", phone_model);
        map.put("phone_system", phone_system);
        map.put("phone_version", phone_version);
        map.put("lat", String.valueOf(lat));
        map.put("lng", String.valueOf(lng));
        return server.register(phone, code, password, imei, phone_model, phone_system, phone_version, lat, lng, SignUtil.getSign(map));
    }
}
